package com.wc.codeforces.博弈.World_is_Mine;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author congge
 * @Date 2024/7/1 0:18
 * @description https://codeforces.com/contest/1987/problem/D
 */
public class Main {
    /**
     * 博弈
     * 思路：
     * 如果我是爱丽丝, 首先我一定是从最小的开始吃, 依次吃大的就好了, 也会想吃单数的
     * 如果我是鲍勃, 我一定是吃单数的, 这样爱丽丝吃不到单数最好, 我吃双数的情况, 爱丽丝有可能能吃到
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 5010;
    static int[] nums = new int[N];
    static boolean[] f = new boolean[N];
    static int n;

    public static void main(String[] args) {
//        int T = sc.nextInt();
        int T = 1;
        while (T-- > 0) {
            solve();
        }
        out.flush();
    }

    static void solve() {
        n = sc.nextInt();
        Arrays.fill(nums, 1, n + 1, 0);
        Arrays.fill(f, 1, n + 1, false);
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            nums[x]++;
        }
        TreeMap<Integer, LinkedList<Integer>> map = new TreeMap<>();
        int res = 0;
        int bob = 0;
        for (int i = 1; i <= n; i++) {
            if (nums[i] > 0) {
                if (!map.containsKey(nums[i])) {
                    map.put(nums[i], new LinkedList<>());
                }
                map.get(nums[i]).add(i);
            }
        }


        // 开始模拟, 爱丽丝能吃就吃
        for (int i = 1; i <= n; i++) {
            if (nums[i] > 0 && !f[i]) {
                f[i] = true;
                bob++;
                res++;
                // Bob从小往大吃
                for (int key : map.keySet()) {
                    if (bob >= key) {
                        LinkedList<Integer> ns = map.get(key);
                        while (ns.size() > 0 && f[ns.getFirst()]) ns.removeFirst();
                        while (ns.size() > 0 && bob >= key) {
                            f[ns.removeFirst()] = true;
                            bob -= key;
                        }
                    } else break;
                }
                Iterator<Map.Entry<Integer, LinkedList<Integer>>> it = map.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry<Integer, LinkedList<Integer>> entry = it.next();
                    int key = entry.getKey();
                    if (map.get(key).size() == 0) it.remove();
                }
            }
        }
        out.println(res);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
